<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    *{margin: 0;padding: 0;}
   
    </style>
</head>
<body>
<button>按钮</button>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>
<script src="js/jquery-3.6.0.min.js"></script>
<script>
$(function(){  
    $("button").click(function(){
        var len=$("li").length;
        $("ul").append("<li>"+(len+1)+"</li>");
    })
    /* $("ul li").live("click",function(){
        $(this).css("background","red");
    }) */   //1.7以后没有
    $("ul").on("click","li",function(){
        $(this).css("background","red");
    })
    $("ul").delegate("li","click",function(){
        $(this).css("background","#000");
    })
})
</script>
</body>
</html>